var jsonString = "";
$.fn.iniTree = function(oo,root){
	jsonString = jsonString+"<li class='root'><input type='checkbox' name='allfun' value='0'/><span>"+root+"</span><ul>";
	for(var i in oo){
		parseJSON(oo[i]);
	}
	jsonString = jsonString+"</ul><li>"
	var treejson = $(jsonString);
	treejson.find('input[@type=checkbox]').click(function(){
						var ch = this.checked;
						$('input[@type=checkbox]',$(this).parent()).each(function(){this.checked = ch;});
	});
	this.append(treejson);
}

var parseJSON = function(obj){
				jsonString=jsonString+"<li><input type='checkbox' name='functionid' value='"+obj.functionid+"'";
				if(obj.checked=='1'){
					jsonString = jsonString +"checked='true'";
				}else{
					//jsonString = jsonString +"checked='false'";
				}
				jsonString=jsonString+"/><span>"+obj.title+"</span>";
				if(obj.children!=null){
					jsonString=jsonString+"<ul>";
					for(var i=0;i<obj.children.length;i++){
						parseJSON(obj.children[i]);
					}
					jsonString=jsonString+"</ul>";
				}
				jsonString=jsonString+"</li>";
				return jsonString;
}
var check = function(){
		var ch = this;
		$('input[@type=checkbox]',$(this).parent()).each(function(){this.checked = ch;});
}